/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package principal;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Juan
 */
public class MServidor extends Thread{
    int port;
    private JFrame ventana;
    ServerSocket ss=null;
    Socket s;
    public MServidor(JFrame ventana,int port){
        this.port=port;
        this.ventana=ventana;
    }
    
    public void run(){   
        try {        
            ss= new ServerSocket(port);
            while (true) {                
               s=ss.accept(); 
                MSGestorConexiones.getInstance().conectaNuevo(new MSConexion(s));
            }
           // JOptionPane.showMessageDialog(ventana, "Se han conectado");
        } catch (NumberFormatException | IOException e) {
           JOptionPane.showMessageDialog(ventana, "Error al abrir el puerto, posiblemente ya esta en uso");
        }
        try {
            ss.close();
        } catch (Exception e) {
        }
    }
}
